﻿using System;
using System.Threading;
using Mono.Collections.Generic;

namespace Mono.Cecil
{
	// Token: 0x020000C7 RID: 199
	public sealed class SecurityDeclaration
	{
		// Token: 0x1700023B RID: 571
		// (get) Token: 0x0600080D RID: 2061 RVA: 0x000240D8 File Offset: 0x000222D8
		// (set) Token: 0x0600080E RID: 2062 RVA: 0x00004EAE File Offset: 0x000030AE
		public SecurityAction Action
		{
			get
			{
				return this.action;
			}
			set
			{
				this.action = value;
			}
		}

		// Token: 0x1700023C RID: 572
		// (get) Token: 0x0600080F RID: 2063 RVA: 0x000240F0 File Offset: 0x000222F0
		public bool HasSecurityAttributes
		{
			get
			{
				this.Resolve();
				return !this.security_attributes.IsNullOrEmpty<SecurityAttribute>();
			}
		}

		// Token: 0x1700023D RID: 573
		// (get) Token: 0x06000810 RID: 2064 RVA: 0x00024118 File Offset: 0x00022318
		public Collection<SecurityAttribute> SecurityAttributes
		{
			get
			{
				this.Resolve();
				bool flag = this.security_attributes == null;
				if (flag)
				{
					Interlocked.CompareExchange<Collection<SecurityAttribute>>(ref this.security_attributes, new Collection<SecurityAttribute>(), null);
				}
				return this.security_attributes;
			}
		}

		// Token: 0x1700023E RID: 574
		// (get) Token: 0x06000811 RID: 2065 RVA: 0x00024158 File Offset: 0x00022358
		internal bool HasImage
		{
			get
			{
				return this.module != null && this.module.HasImage;
			}
		}

		// Token: 0x06000812 RID: 2066 RVA: 0x00004EB8 File Offset: 0x000030B8
		internal SecurityDeclaration(SecurityAction action, uint signature, ModuleDefinition module)
		{
			this.action = action;
			this.signature = signature;
			this.module = module;
		}

		// Token: 0x06000813 RID: 2067 RVA: 0x00004ED7 File Offset: 0x000030D7
		public SecurityDeclaration(SecurityAction action)
		{
			this.action = action;
			this.resolved = true;
		}

		// Token: 0x06000814 RID: 2068 RVA: 0x00004EEF File Offset: 0x000030EF
		public SecurityDeclaration(SecurityAction action, byte[] blob)
		{
			this.action = action;
			this.resolved = false;
			this.blob = blob;
		}

		// Token: 0x06000815 RID: 2069 RVA: 0x00024180 File Offset: 0x00022380
		public byte[] GetBlob()
		{
			bool flag = this.blob != null;
			byte[] result;
			if (flag)
			{
				result = this.blob;
			}
			else
			{
				bool flag2 = !this.HasImage || this.signature == 0U;
				if (flag2)
				{
					throw new NotSupportedException();
				}
				result = this.module.Read<SecurityDeclaration, byte[]>(ref this.blob, this, (SecurityDeclaration declaration, MetadataReader reader) => reader.ReadSecurityDeclarationBlob(declaration.signature));
			}
			return result;
		}

		// Token: 0x06000816 RID: 2070 RVA: 0x000241F8 File Offset: 0x000223F8
		private void Resolve()
		{
			bool flag = this.resolved || !this.HasImage;
			if (!flag)
			{
				object syncRoot = this.module.SyncRoot;
				lock (syncRoot)
				{
					bool flag3 = this.resolved;
					if (!flag3)
					{
						this.module.Read<SecurityDeclaration>(this, delegate(SecurityDeclaration declaration, MetadataReader reader)
						{
							reader.ReadSecurityDeclarationSignature(declaration);
						});
						this.resolved = true;
					}
				}
			}
		}

		// Token: 0x040002D0 RID: 720
		internal readonly uint signature;

		// Token: 0x040002D1 RID: 721
		private byte[] blob;

		// Token: 0x040002D2 RID: 722
		private readonly ModuleDefinition module;

		// Token: 0x040002D3 RID: 723
		internal bool resolved;

		// Token: 0x040002D4 RID: 724
		private SecurityAction action;

		// Token: 0x040002D5 RID: 725
		internal Collection<SecurityAttribute> security_attributes;
	}
}
